$(function(){
    obj.init();
});

var obj = new function () {
    'use strict';
    return {
        appId: null,
        dataGrid: null,
        init: function () {
            this.appId     = xhTool.getQuery('appId');
            this.dataGrid = new xhDataGrid($('#history_list'), 'Appserver/getHistoryVersion', {appId:this.appId});
            this.dataGrid.parseToolbar().init().activeBtn($('#bt_history_del'), $('#bt_school_app'));
            this.listener();
        },
        listener: function () {
            var $this = this;
            //删除
            $('#bt_history_del').click(function () {
                if (xhExtra.buttonDisabled($(this))) return false;
                $this.funObj().deleteHistory();
            });
            //更新至学校
            $('#bt_school_app').click(function () {
                if(xhExtra.buttonDisabled($(this))) return false;
                window.top.xhTop.showModal({
                    title: '选择学校',
                    content: xhTool.getFrameString('School/schoolChoose', {callback: 'obj.funObj().addAppToSchool', single: 'false', param: $this.dataGrid.getSelectValue('versionCode')}, 500),
                    size: 'lg',
                    button: '确认'
                });
            });
        },
        funObj: function(){
            var $this = this;
            var appId = this.appId;
            return {
                deleteHistory: function () {
                    var versionCode = $this.dataGrid.getSelectValue('versionCode');
                    xhExtra.askChangeStatus('Appserver/delHistory', {versionCode: versionCode, appId: appId}, $this.dataGrid, '确认删除？');
                }
            }
        }
    }
};